<?php
namespace app\index\controller;

use app\index\model\Archives;
use app\index\model\ArchivesCategory;
use app\index\model\Archives_file;
use app\index\model\Arc_extend_info;
use app\index\model\Collect;
use app\index\model\CollectArchivesRelation;
use app\index\model\FileLog;
use app\index\model\Storeroom;
use app\index\model\Tag;
use app\index\model\TagArchivesRelation;
use app\index\model\TagGroup;
use app\index\model\User;
use think\Controller;
use think\Db;
use think\Request;
use think\Session;

// use app\index\model\Prearc_model;

class Prearc extends Common {
	protected $request;
	protected $ac_model;
	protected $a_model;
	protected $acf_model;
	protected $fl_model;
	protected $tag_model;
	protected $tag_group_model;
	protected $tag_archives_relation_model;
	protected $storage_model;
	protected $cate_id;
	protected $aei_model;
	protected $user_model;
	protected $condition = array();
	public function __construct(Request $request = null) {
		parent::__construct($request);
		$this->request = $request;
		$this->ac_model = new ArchivesCategory();
		$this->a_model = new Archives();
		$this->acf_model = new Archives_file();
		$this->fl_model = new FileLog();
		$this->tag_model = new Tag();
		$this->tag_archives_relation_model = new TagArchivesRelation();
		$this->tag_group_model = new TagGroup();
		$this->storage_model = new Storeroom();
		$this->aei_model = new Arc_extend_info();
		$this->user_model = new User();

		$this->condition['cate_type'] = 1;
		/* //不是管理员的情况下  只看自己和 自己下面部门的文件
			         if($_SESSION['think']['username'][0]['user_name'] != 'admin'){
			             $condition['create_user_id'] =$_SESSION['think']['username'][0]['user_id'];
		*/
		$cond = $this->getRoleByUser();
		if ($cond != 'all') {
			$this->condition['create_user_id'] = array('in', $cond);
		}
	}

	// 预归档
	public function index() {
		$cate_id = $this->request->get('cate_id');
		// var_dump($cate_id);die;
		//看部门或者只看自己
		$type = $this->request->get('type', '');
		$cond = $this->getRoleByUser();
		$uid = $_SESSION['think']['username'][0]['user_id'];
		$user_data = $this->user_model->find($uid);
		$bid = $this->getOrgIdByUid($uid);
		if (empty($cate_id)) {
			$cate_id = session('cate_id') ? session('cate_id') : 1;
		} else {
			session('cate_id', $cate_id);
		}
		if ($type == 'self') {
			$ac_data = $this->ac_model->getListByCondition(['cate_type' => 1, 'create_user_id' => $_SESSION['think']['username'][0]['user_id']]);
			$a_data = $this->a_model->getListByConditionPage(array('category_id' => $cate_id, 'create_user_id' => $_SESSION['think']['username'][0]['user_id']));
		} else {
			if ($cond != 'all') {

				if ($user_data['level']) {
					$all_org_id = $this->getAllOrgId($bid);
					$ac_data = $this->ac_model->getListByCondition(['cate_type' => 1, 'create_org_id' => array('in', $all_org_id)]);
					$a_data = $this->a_model->getListByConditionPage(array('category_id' => $cate_id, 'create_org_id' => array('in', $all_org_id)), array('create_time desc'));
				} else {
					$ac_data = $this->ac_model->getListByCondition(['cate_type' => 1, 'create_org_id' => $bid]);
					$a_data = $this->a_model->getListByConditionPage(array('category_id' => $cate_id, 'create_user_id' => array('in', $cond)), array('create_time desc'));
				}
			} else {
				$ac_data = $this->ac_model->getListByCondition($this->condition);

				$a_data = $this->a_model->getListByConditionPage(array('category_id' => $cate_id), array('create_time desc'));
			}
		}
		// dump($this->condition);die;
		$page = $a_data->render();
		$a_data = $a_data->toArray()['data'];
		foreach ($a_data as $key => $item) {
			$a_data[$key]['username'] = $this->user_model->where('user_id', $item['create_user_id'])->value('user_name');
		}

		$nav_html = '';
		$tree = '';
		if ($ac_data) {
			$cate_tree = recursionCate($ac_data, 'cate_id', 0, 'cate_parent_id');
			$tree = createCateTree($cate_tree, 'cate_id', 'cate_parent_id', 'cate_name');
			if (!empty($cate_id) && $cate_id != -1 && $cate_id != -2 && $cate_id != -3) {
				$nav = trim(getAncestors(arrayValueToKey($ac_data, 'cate_id'), $cate_id, 0), ',');
				$nav = explode(',', $nav);
				$nav = array_reverse($nav, true);
				foreach ($nav as $k => $v) {
					$p = explode('-', $v);
					if ($type !== 'self') {
						$nav_html .= '<li>' .
						'<a data-id="' . $p[0] . '" href="' . url('index/prearc/index') . '">' . $p[1] . '</a>' .
							'<i class="fa fa-angle-right"></i>' .
							'</li>';
					} else {
						$nav_html .= '<li>' .
						'<a data-id="' . $p[0] . '" href="' . url('index/prearc/index') . '?type=self">' . $p[1] . '</a>' .
							'<i class="fa fa-angle-right"></i>' .
							'</li>';
					}

				}
			}
		}
		unset($_SESSION['cate_id']);
		return view('index@Prearc/index', ['tree' => $tree, 'nav_html' => $nav_html, 'a_data' => $a_data, 'type' => $type, 'page' => $page]);
	}
	//添加文件夹
	public function addFolder() {
		$this->getAuth();

		$this->autoCreate('folder');
		return view('index@Prearc/addFolder');
	}
	//添加word文档
	public function addWord() {
		$this->getAuth();

		$this->autoCreate('word');
		return view('index@Prearc/addWord');
	}
	//添加Excel文档
	public function addExcel() {
		$this->getAuth();

		$this->autoCreate('excel');
		return view('index@Prearc/addExcel');
	}
	//添加Txt文档
	public function addTxt() {
		$this->getAuth();

		$this->autoCreate('txt');
		return view('index@Prearc/addTxt');
	}
	//添加Html文档
	public function addHtml() {
		$this->getAuth();

		$this->autoCreate('html');
		return view('index@Prearc/addHtml');
	}
	//添加Ppt文档
	public function addPpt() {
		$this->getAuth();

		$this->autoCreate('ppt');
		return view('index@Prearc/addPpt');
	}
	//删除 编辑文件夹
	public function folderEdit() {
		$this->getAuth();

		$cate_id = \session('cate_id');
		if (empty($cate_id) || $cate_id == -1) {
			jsonOut(0, '请先选择文件夹后存在操作');
		}
		$this->folderEdits(1);
		$cate_data = $this->ac_model->getDataByCondition(array('cate_id' => $cate_id));
		return view('index@Prearc/folderEdit', ['data' => $cate_data]);
	}

	//文件重命名
	public function rename() {
		$this->getAuth();

		$params = array();

		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));
		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;
		if ($this->request->instance()->isPost()) {
			$name = $this->request->post('name', '');
			$describe = $this->request->post('describe', '');
			if (empty($name)) {
				jsonOut(0, '文件名不能为空');
			}
			//将对于的文件重命名
			$cate_id = session('cate_id');
			$has_name = $this->a_model->where('arc_name', $name)->where('arc_id', '<>', $id)->count();
			if ($has_name != 0) {
				jsonOut(0, '文件已存在');
			}
			// $path = $this->getFilePath($cate_id, 1, $data['arc_id']);
			// if (is_file($path['path'] . '/' . $name . '.' . $data['arc_type'])) {
			// 	jsonOut(0, '文件已存在');
			// }

			// $rm = rename($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type'], $path['path'] . '/' . $name . '.' . $data['arc_type']);
			$res = $this->acf_model->where(array('arc_id' => $id))->find();
			$res1 = $this->fl_model->where(array('file_id' => $res['file_id']))->find();
			$types = explode(".", $res1['file_old_name']);
			$newname = $name . '.' . end($types);
			$rm = $this->fl_model->where('file_id', $res['file_id'])->update(['file_old_name' => $newname]);
			if ($rm) {
				$save_data = array(
					'arc_name' => $name,
					'arc_desc' => $describe,
					'update_user_id' => $this->admin_session['id'],
					'update_time' => date('Y-m-d H:i:s'),
				);
				if ($this->a_model->updateByCondition(array('arc_id' => $id), $save_data)) {
					//操作记录
					$this->tableBak('archives', 'archives_version', 'arc_id', 'original_id', $id, 'backup_reasons', '重命名');
					//重命名记录保存
					$uid = $_SESSION['think']['username'][0]['user_id'];
					$time = date('Y-m-d H:i:s', time());

					//记录用户操作
					$note = [
						'file_id' => $id,
						'file_record' => 4,
						'file_log_desc' => '重命名文件',
						'create_user_id' => $uid,
						'create_time' => $time,
					];
					$record = Db::table('cn_file_record')
						->insert($note);
					jsonOut(1, '操作成功');
				} else {
					jsonOut(0, '操作失败');
				}
			} else {
				jsonOut(0, '操作失败');
			}
		}
		return view('index@Prearc/rename', $params);
	}
	//复制文件
	public function copy() {
		$this->getAuth();

		$params = array();
		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));

		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;
		$ac_data = $this->ac_model->getListByCondition($this->condition);
		$cate_tree = recursionCate($ac_data, 'cate_id', 0, 'cate_parent_id');
		$tree = createCateTree($cate_tree, 'cate_id', 'cate_parent_id', 'cate_name');
		if (empty($tree)) {
			jsonOut(0, '文件目录错误');
		}
		$params['tree'] = $tree;
		if ($this->request->instance()->isPost()) {
			$cate_id = $this->request->param('cate_id', '');
			$new_cate = $this->request->param('new_cate', '');
			if (empty($cate_id) || empty($new_cate)) {
				jsonOut(0, '参数错误');
			}
			$path = $this->getFilePath($cate_id, 1, $data['arc_id']);
			$new_path = $this->getFilePath($new_cate, 1, $data['arc_id']);
			$table1 = config('database.prefix') . 'archives';
			$new_data = Db::table($table1)->where(array('arc_id' => $id))->find();
			$save_data = $new_data;
			unset($save_data['arc_id']);
			unset($save_data['audit_status']);
			unset($save_data['is_delete']);
			$save_data['create_user_id'] = $this->admin_session['id'];
			$save_data['update_user_id'] = $this->admin_session['id'];
			$save_data['create_time'] = date('Y-m-d H:i:s');
			$save_data['update_time'] = date('Y-m-d H:i:s');
			$save_data['category_id'] = $new_cate;
			if (is_file($new_path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type'])) {
				jsonOut(0, '文件已存在');
			}
			$cp = copy($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type'], $new_path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
			if ($cp) {
				if ($this->a_model->insert($save_data)) {
					$id = $this->a_model->getLastInsID();
					$this->tableBak('archives', 'archives_version', 'arc_id', 'original_id', $id, 'backup_reasons', '复制');
					//复制文件记录保存
					$uid = $_SESSION['think']['username'][0]['user_id'];
					$time = date('Y-m-d H:i:s', time());

					//记录用户操作
					$note = [
						'file_id' => $id,
						'file_record' => 5,
						'file_log_desc' => '复制文件',
						'create_user_id' => $uid,
						'create_time' => $time,
					];
					$record = Db::table('cn_file_record')
						->insert($note);
					jsonOut(1, '操作成功');
				}
				@unlink($new_path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
				jsonOut(0, '操作失败');

			} else {
				jsonOut(0, '操作失败');
			}
		}
		return view('index@Prearc/copy', $params);
	}
	//移动文件
	public function remove() {
		$this->getAuth();

		$params = array();

		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));

		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;
		$ac_data = $this->ac_model->getListByCondition($this->condition);
		$cate_tree = recursionCate($ac_data, 'cate_id', 0, 'cate_parent_id');
		$tree = createCateTree($cate_tree, 'cate_id', 'cate_parent_id', 'cate_name');
		if (empty($tree)) {
			jsonOut(0, '文件目录错误');
		}

		$params['tree'] = $tree;
		if ($this->request->instance()->isPost()) {
			$params = Session::get('file_id');

			$cate_id = $this->request->param('cate_id', '');
			$new_cate = $this->request->param('new_cate', '');
			if (empty($cate_id) || empty($new_cate)) {
				jsonOut(0, '参数错误');
			}
			$res = $this->a_model->where('arc_id', $id)->update(['category_id' => $new_cate]);
			if ($res) {
				jsonOut(1, '操作成功');
			} else {
				jsonOut(0, '操作失败');
			}
			//        		$path = $this->getFilePath($cate_id, 1, $data['arc_id']);
			//        		$new_path = $this->getFilePath($new_cate, 1, $data['arc_id']);
			//        		$save_data['category_id'] = $new_cate;
			//        		if (is_file($new_path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type'])) {
			//        			jsonOut(0, '文件已存在');
			//        		}
			//        		$cp = copy($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type'], $new_path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
			//        		if ($cp) {
			//        			if ($this->a_model->updateByCondition(array('arc_id' => $id), array('category_id' => $new_cate))) {
			//        				@unlink($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
			//        				$this->tableBak('archives', 'archives_version', 'arc_id', 'original_id', $id, 'backup_reasons', '移动');
			// //移动文件记录保存
			//        				$uid = $_SESSION['think']['username'][0]['user_id'];
			//        				$time = date('Y-m-d H:i:s', time());

			// //记录用户操作
			//        				$note = [
			//        					'file_id' => $id,
			//        					'file_record' => 6,
			//        					'file_log_desc' => '移动文件',
			//        					'create_user_id' => $uid,
			//        					'create_time' => $time,
			//        				];
			//        				$record = Db::table('cn_file_record')
			//        				->insert($note);
			//        				jsonOut(1, '操作成功');
			//        			} else {
			//        				jsonOut(0, '操作失败');
			//        			}
			//        		} else {
			//        			jsonOut(0, '操作失败');
			//        		}
		}
		// echo json_encode($params['tree']);exit;
		// var_dump($params);die;
		return view('index@Prearc/remove', $params);
	}
	//删除文件
	public function delete() {
		$this->getAuth();

		$params = array();
		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));

		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;
		if ($this->request->instance()->isPost()) {
			//文件删除重写部分
			$f_type = $this->a_model->get($id);
			if ($f_type['audit_status'] != '0') {
				jsonOut(0, '该文件正在归档,无法删除!');
			}

			// $path = $this->getFilePath(session('cate_id'), 1, $data['arc_id']); //取路径地址
			// $unlink = @unlink($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']); //删除文件
			// if ($unlink) {
			// 	$del = $this->a_model->updateByCondition(array('arc_id' => $id), array('is_delete' => 1));
			// 	if ($del) {
			// 		$this->tableBak('archives', 'archives_version', 'arc_id', 'original_id', $id, 'backup_reasons', '删除');
			// 		//删除文件记录保存
			// 		$uid = $_SESSION['think']['username'][0]['user_id'];
			// 		$time = date('Y-m-d H:i:s', time());
			// 		//记录用户操作
			// 		$note = [
			// 			'file_id' => $id,
			// 			'file_record' => 7,
			// 			'file_log_desc' => '删除文件',
			// 			'create_user_id' => $uid,
			// 			'create_time' => $time,
			// 		];
			// 		$record = Db::table('cn_file_record')
			// 		->insert($note);
			// 		jsonOut(1, '删除成功');
			// 	} else {
			// 		//@unlink(iconv("UTF-8", "GBK", $this->folderPath.'/delete_all/' . $data['arc_name'] . '.' . $data['arc_type']));
			// 		jsonOut(1, '文件已删除,数据更新失败！');
			// 	}
			// } else {
			// 	jsonOut(0, '文件不存在', $path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
			// }
			$ress = $this->a_model->where('arc_id', $id)->update(['is_delete' => 1]);
			if ($ress) {
				jsonOut(1, '删除成功');
			} else {
				jsonOut(0, '删除失败');
			}
			/*if ($this->a_model->updateByCondition(array('arc_id' => $id), array('is_delete' => 1))) {
				                $this->tableBak('archives', 'archives_version', 'arc_id', 'original_id', $id, 'backup_reasons', '删除');
				                //删除文件记录保存
				                $uid = $_SESSION['think']['username'][0]['user_id'];
				                $time =  date('Y-m-d H:i:s',time());

				                //记录用户操作
				                $note = [
				                    'file_id' => $id,
				                    'file_record' => 7,
				                    'file_log_desc' => '删除文件',
				                    'create_user_id' => $uid,
				                    'create_time' => $time
				                ];
				                $record = Db::table('cn_file_record')
				                    ->insert($note);
				                $path = $this->getFilePath(session('cate_id'));
				                $a = @unlink($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
				                dump($a);dump($path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);die;
				                if($a){
				                    $del = $this->a_model->updateByCondition(array('arc_id' => $id), array('is_delete' => 1));
				                    if ($del === 0) {
				                        jsonOut(1, '删除成功');
				                    }else{
				                        //@unlink(iconv("UTF-8", "GBK", $this->folderPath.'/delete_all/' . $data['arc_name'] . '.' . $data['arc_type']));
				                        jsonOut(1, '删除失败');
				                    }
				                }else{
				                    jsonOut(0,'文件不存在',$path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']);
				                }
				                //jsonOut(1, '删除成功');
				            }else{
				                jsonOut(1, '删除失败');
			*/
			/*****************移动并删除的逻辑*******************/
			//            $path = $this->getFilePath(session('cate_id'));
			/*$cp = copy(iconv("UTF-8", "GBK",$path['path'].'/'.$data['arc_name'].'.'.$data['arc_type']),iconv("UTF-8", "GBK",$this->folderPath.'/delete_all/'.$data['arc_name'].'.'.$data['arc_type']));
	            if($cp) {
	                if ($this->a_model->updateByCondition(array('arc_id' => $id), array('is_delete' => 1))) {
	                    @unlink(iconv("UTF-8", "GBK", $path['path'] . '/' . $data['arc_name'] . '.' . $data['arc_type']));
	                    jsonOut(1, '删除成功');
	                }else{
	                    @unlink(iconv("UTF-8", "GBK", $this->folderPath.'/delete_all/' . $data['arc_name'] . '.' . $data['arc_type']));
	                    jsonOut(1, '删除失败');
	                }
	            }else{
	                @unlink(iconv("UTF-8", "GBK", $this->folderPath.'/delete_all/' . $data['arc_name'] . '.' . $data['arc_type']));
	                jsonOut(1, '删除失败');
*/
		}
		return view('index@Prearc/delete', $params);
	}
	//收藏文件
	public function shouc() {
		$this->getAuth();

		$params = array();
		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));

		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;

		if ($this->request->instance()->isPost()) {
			//先创建 收藏表数据
			$collect = new Collect();
			$collect_arc = new CollectArchivesRelation();
			//先查询用户是否已经收藏过
			$f_data = $collect_arc->getDataByCondition(array('arc_id' => $id, 'create_user_id' => $this->admin_session['id']));
			if ($f_data) {
				jsonOut(0, '您已经收藏过了');
			}
			$c_data = array(
				'create_user_id' => $this->admin_session['id'],
				'create_time' => date('Y-m-d H:i:s'),
				'update_user_id' => $this->admin_session['id'],
				'update_time' => date('Y-m-d H:i:s'),
				'is_delete' => 0,
			);
			if ($collect->insert($c_data)) {
				//插入收藏关联表
				$ca_data = array(
					'arc_id' => $id,
					'col_id' => $collect->getLastInsID(),
					'create_user_id' => $this->admin_session['id'],
					'create_time' => date('Y-m-d H:i:s'),
					'update_user_id' => $this->admin_session['id'],
					'update_time' => date('Y-m-d H:i:s'),
				);
				if ($collect_arc->insert($ca_data)) {
					//收藏文件记录保存
					$uid = $_SESSION['think']['username'][0]['user_id'];
					$time = date('Y-m-d H:i:s', time());

					//记录用户操作
					$note = [
						'file_id' => $id,
						'file_record' => 3,
						'file_log_desc' => '收藏文件',
						'create_user_id' => $uid,
						'create_time' => $time,
					];
					$record = Db::table('cn_file_record')
						->insert($note);
					jsonOut(1, '收藏成功');
				} else {
					jsonOut(0, '收藏失败');
				}
			}
		}
		return view('index@Prearc/shouc', $params);
	}
	//下载原文件
	public function download() {
		$this->getAuth();

		$id = $this->request->param('id', '');
		// var_dump($id);die;
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		//下载原文件记录保存
		$uid = $_SESSION['think']['username'][0]['user_id'];
		$time = date('Y-m-d H:i:s', time());

		//记录用户操作
		$note = [
			'file_id' => $id,
			'file_record' => 1,
			'file_log_desc' => '下载源文件',
			'create_user_id' => $uid,
			'create_time' => $time,
		];
		$record = Db::table('cn_file_record')
			->insert($note);
		$this->toDownload($id);
	}
	//指定标签
	public function settag() {
		$this->getAuth();

		$params = array();
		$id = $this->request->param('id', 0);
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));

		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$params['data'] = $data;

		//指定标签记录保存
		$uid = $_SESSION['think']['username'][0]['user_id'];
		$time = date('Y-m-d H:i:s', time());

		//记录用户操作
		$note = [
			'file_id' => $id,
			'file_record' => 2,
			'file_log_desc' => '指定标签',
			'create_user_id' => $uid,
			'create_time' => $time,
		];
		$record = Db::table('cn_file_record')
			->insert($note);
		return view('index@Prearc/settag', $params);
	}
	//设置标签
	public function settags() {
		$this->getAuth();

		$params = array();
		//取标签组
		$tag_group_data = $this->tag_group_model->getListByCondition(array(), 'tag_group_sort desc');
		$params['tgd'] = $tag_group_data;
		//先去第组下面的对应的标签的第一个显示为上级标签
		$tag_data = $this->tag_model->getListByCondition(array('tag_group_id' => $tag_group_data[0]['tag_gruop_id'], 'tag_parent_id' => 0), 'tag_sort desc');
		$params['tds'] = $tag_data;
		if ($this->request->instance()->isPost()) {
			$tag_val = $this->request->post('tag_val', ''); //1添加标签组 2添加标签
			if (empty($tag_val)) {
				jsonOut(0, '参数错误');
			}
			if ($tag_val == 1) {
				$tag = $this->request->post('tag', '');
				$ptag = $this->request->post('ptag', 0);
				$gtag = $this->request->post('gtag', 0);
				$otag = $this->request->post('otag', 99);
				if (empty($tag)) {
					jsonOut(0, '添加信息不全');
				}
				$save_data = array(
					'tag_name' => $tag,
					'tag_sort' => $otag,
					'tag_parent_id' => $ptag,
					'tag_group_id' => $gtag,
					'create_user_id' => $this->admin_session['id'],
					'create_time' => date('Y-m-d H:i:s'),
					'update_user_id' => $this->admin_session['id'],
					'update_time' => date('Y-m-d H:i:s'),
				);
				if ($this->tag_model->insert($save_data)) {
					jsonOut(1, '添加标签成功');
				} else {
					jsonOut(0, '添加失败');
				}
			} else {
				$tags = $this->request->post('tags', '');
				$otags = $this->request->post('otags', 99);
				$is_only = $this->request->post('is_only', 0);
				$is_required = $this->request->post('is_required', 0);
				if (empty($tags)) {
					jsonOut(0, '标签组名称错误');
				}
				$save_data = array(
					'tag_group_name' => $tags,
					'tag_group_sort' => $otags,
					'is_only' => $is_only,
					'is_required' => $is_required,
					'create_user_id' => $this->admin_session['id'],
					'create_time' => date('Y-m-d H:i:s'),
					'update_user_id' => $this->admin_session['id'],
					'update_time' => date('Y-m-d H:i:s'),
				);
				if ($this->tag_group_model->insert($save_data)) {
					jsonOut(1, '添加标签组成功');
				} else {
					jsonOut(0, '添加失败');
				}
			}
		}
		return view('index@Prearc/settags', $params);
	}
	//获取标签
	public function getTags() {
		$id = $this->request->post('id', '');
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->tag_model->getListByCondition(array('tag_group_id' => $id, 'tag_parent_id' => 0), 'tag_sort desc');
		if (empty($data)) {
			jsonOut(0, '暂无数据');
		} else {
			jsonOut(1, '查询成功', $data);
		}
	}
	//修改标签组
	public function updateTags() {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('tagsid', '');
			$tags_name = $this->request->post('tags', '');
			$otags = $this->request->post('otags', 99);
			$is_only = $this->request->post('is_only', 0);
			$is_required = $this->request->post('is_required', 0);
			if (empty($id) || empty($tags_name)) {
				jsonOut(0, '名称不能为空');
			}
			$save_data = array(
				'tag_group_name' => $tags_name,
				'tag_group_sort' => $otags,
				'is_only' => $is_only,
				'is_required' => $is_required,
				'update_user_id' => $this->admin_session['id'],
				'update_time' => date('Y-m-d H:i:s'),
			);
			if ($this->tag_group_model->updateByCondition(array('tag_gruop_id' => $id), $save_data)) {
				jsonOut(1, '编辑成功');
			} else {
				jsonOut(0, '编辑失败');
			}
		}
	}
	//修改标签
	public function updateTag() {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('tagid', '');
			$tag_name = $this->request->post('tag', '');
			$otag = $this->request->post('otag', 99);
			if (empty($id) || empty($tag_name)) {
				jsonOut(0, '名称不能为空');
			}
			$save_data = array(
				'tag_name' => $tag_name,
				'tag_sort' => $otag,
				'update_user_id' => $this->admin_session['id'],
				'update_time' => date('Y-m-d H:i:s'),
			);
			if ($this->tag_model->updateByCondition(array('tag_id' => $id), $save_data)) {
				jsonOut(1, '编辑成功');
			} else {
				jsonOut(0, '编辑失败');
			}
		}
	}
	//删除标签或者标签组
	public function deleteTag() {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$tag_type = $this->request->post('tag_type', '');
			$tag_val = $this->request->post('tag_val', '');
			if (empty($tag_val) || empty($tag_type)) {
				jsonOut(0, '参数错误');
			}
			if ($tag_type == 1) {
				$tag_group_data = $this->tag_group_model->getDataByCondition(array('tag_gruop_id' => $tag_val));
				if (empty($tag_group_data)) {
					jsonOut(0, '暂无数据');
				}
				//查询下面是否存在未删除的标签
				$f_tag = $this->tag_model->getDataByCondition(array('tag_group_id' => $tag_val, 'is_delete' => 0));
				if (empty($f_tag)) {
					//下面没有未删除的标签 可以删除
					if ($this->tag_group_model->updateByCondition(array('tag_gruop_id' => $tag_val), array('is_delete' => 1))) {
						jsonOut(1, '标签组删除成功');
					} else {
						jsonOut(0, '标签组删除失败');
					}
				} else {
					jsonOut(0, '标签组下存在未删除的标签，请先删除标签后重试');
				}
			} else {
				$tag_data = $this->tag_model->getDataByCondition(array('tag_id' => $tag_val));
				if (empty($tag_data)) {
					jsonOut(0, '暂无数据');
				}
				if ($tag_data['tag_parent_id'] == 0) {
					//一级标签 先看下面有没有没有删除的标签
					$f_tag_data = $this->tag_model->getDataByCondition(array('tag_parent_id' => $tag_val, 'is_delete' => 0));
					if (empty($f_tag_data)) {
						//下面没有未删除的标签 可以删除
						if ($this->tag_model->updateByCondition(array('tag_id' => $tag_val), array('is_delete' => 1))) {
							jsonOut(1, '删除标签成功');
						} else {
							jsonOut(0, '删除标签失败');
						}
					} else {
						jsonOut(0, '标签存在下级标签，请先删除下级标签后重试');
					}
				} else {
					//二级标签 直接删除
					if ($this->tag_model->updateByCondition(array('tag_id' => $tag_val), array('is_delete' => 1))) {
						jsonOut(1, '删除标签成功');
					} else {
						jsonOut(0, '删除标签失败');
					}
				}
			}
		}
	}
	//获取标签树结构
	public function getTagsTree() {
		$tags = $this->tag_group_model->getListByCondition(array(), 'tag_group_sort desc');
		$html = '';
		if ($tags) {
			foreach ($tags as $key => $val) {
				if ($val['is_only'] == 1) {
					$is_only = '（单选）';
				} else {
					$is_only = '（多选）';
				}
				$html .= '<tr>' .
					'<td class="highlight">' .
					'<div class="success"></div>' .
					'<a href="javascript:;">' . $val['tag_group_name'] . $is_only . '</a>' .
					'</td>' .
					'<td>' .
					'</td>' .
					'<td>' .
					'</td>' .
					'<td>' .
					'<a href="javascript:;" class="btn default btn-xs purple editBtn" data-tagname="' . $val['tag_group_name'] . '" data-order="' . $val['tag_group_sort'] . '" data-only="' . $val['is_only'] . '" data-required="' . $val['is_required'] . '" data-type="1" data-id="' . $val['tag_gruop_id'] . '">' .
					'<i class="fa fa-edit"></i> 编辑' .
					'</a>' .
					'<a href="javascript:;" class="btn default btn-xs black delBtn" data-tagname="' . $val['tag_group_name'] . '" data-type="1" data-id="' . $val['tag_gruop_id'] . '">' .
					'<i class="fa fa-trash-o"></i> 删除' .
					'</a>' .
					'</td>' .
					'</tr>';
				$otag = $this->tag_model->getListByCondition(array('tag_group_id' => $val['tag_gruop_id'], 'tag_parent_id' => 0), 'tag_sort desc');
				if ($otag) {
					foreach ($otag as $k => $v) {
						$html .= '<tr>' .
							'<td class="highlight">' .
							'<div class="info"></div>|--' .
							'</td>' .
							'<td>' .
							'<a href="javascript:;">' . $v['tag_name'] . '</a>' .
							'</td>' .
							'<td>' .
							'</td>' .
							'<td>' .
							'<a href="javascript:;" class="btn default btn-xs purple editBtn" data-tagname="' . $v['tag_name'] . '" data-order="' . $v['tag_sort'] . '" data-type="2"  data-id="' . $v['tag_id'] . '">' .
							'<i class="fa fa-edit"></i> 编辑' .
							'</a>' .
							'<a href="javascript:;" class="btn default btn-xs black delBtn" data-tagname="' . $v['tag_name'] . '"  data-type="2"  data-id="' . $v['tag_id'] . '">' .
							'<i class="fa fa-trash-o"></i> 删除' .
							'</a>' .
							'</td>' .
							'</tr>';
						$ttag = $this->tag_model->getListByCondition(array('tag_group_id' => $val['tag_gruop_id'], 'tag_parent_id' => $v['tag_id']), 'tag_sort desc');
						if ($ttag) {
							foreach ($ttag as $k1 => $v1) {
								$html .= '<tr>' .
									'<td class="highlight">' .
									'<div class="warning"></div>' .
									'</td>' .
									'<td>|--' .
									'</td>' .
									'<td>' .
									'<a href="javascript:;">' . $v1['tag_name'] . '</a>' .
									'</td>' .
									'<td>' .
									'<a href="javascript:;" class="btn default btn-xs purple editBtn"  data-tagname="' . $v1['tag_name'] . '" data-order="' . $v1['tag_sort'] . '"  data-type="2"  data-id="' . $v1['tag_id'] . '">' .
									'<i class="fa fa-edit"></i> 编辑' .
									'</a>' .
									'<a href="javascript:;" class="btn default btn-xs black delBtn" data-tagname="' . $v1['tag_name'] . '" data-type="2"  data-id="' . $v1['tag_id'] . '">' .
									'<i class="fa fa-trash-o"></i> 删除' .
									'</a>' .
									'</td>' .
									'</tr>';
							}
						}
					}
				}

			}
		}
		jsonOut(1, '查询成功', $html);
	}
	//获取标签树结构
	public function getTagsTree1() {
		$tags = $this->tag_group_model->getListByCondition(array(), 'tag_group_sort desc');
		$html = '';
		if ($tags) {
			foreach ($tags as $key => $val) {
				if ($val['is_only'] == 1) {
					$is_only = '（单选）';
				} else {
					$is_only = '（多选）';
				}
				$html .= '<tr>' .
					'<td class="highlight">' .
					'<div class="success"></div>' .
					'<a href="javascript:;">' . $val['tag_group_name'] . $is_only . '</a>' .
					'</td>' .
					'<td>' .
					'</td>' .
					'<td>' .
					'</td>' .
					'<td>' .
					'</td>' .
					'</tr>';
				$otag = $this->tag_model->getListByCondition(array('tag_group_id' => $val['tag_gruop_id'], 'tag_parent_id' => 0), 'tag_sort desc');
				if ($otag) {
					foreach ($otag as $k => $v) {
						$html .= '<tr>' .
							'<td class="highlight">' .
							'<div class="info"></div>|--' .
							'</td>' .
							'<td>' .
							'<a href="javascript:;">' . $v['tag_name'] . '</a>' .
							'</td>' .
							'<td>' .
							'</td>' .
							'<td>' .
							'<a href="javascript:;" class="btn default btn-xs blue editBtn" data-tagname="' . $v['tag_name'] . '" data-order="' . $v['tag_sort'] . '" data-type="2"  data-id="' . $v['tag_id'] . '">' .
							'<i class="fa fa-check-square"></i> 设置标签' .
							'</a>' .
							'</td>' .
							'</tr>';
						$ttag = $this->tag_model->getListByCondition(array('tag_group_id' => $val['tag_gruop_id'], 'tag_parent_id' => $v['tag_id']), 'tag_sort desc');
						if ($ttag) {
							foreach ($ttag as $k1 => $v1) {
								$html .= '<tr>' .
									'<td class="highlight">' .
									'<div class="warning"></div>' .
									'</td>' .
									'<td>|--' .
									'</td>' .
									'<td>' .
									'<a href="javascript:;">' . $v1['tag_name'] . '</a>' .
									'</td>' .
									'<td>' .
									'<a href="javascript:;" class="btn default btn-xs blue editBtn"  data-tagname="' . $v1['tag_name'] . '" data-order="' . $v1['tag_sort'] . '"  data-type="2"  data-id="' . $v1['tag_id'] . '">' .
									'<i class="fa fa-check-square"></i> 设置标签' .
									'</a>' .
									'</td>' .
									'</tr>';
							}
						}
					}
				}

			}
		}
		jsonOut(1, '查询成功', $html);
	}
	//设置cate_id
	public function setCateId() {
		$cate_id = $this->request->post('cate_id', 0);
		session('cate_id', $cate_id);
		jsonOut(1, '设置成功');

	}
	//获取标签数据
	public function getTagsData() {
		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('id', '');
			if (empty($id)) {
				jsonOut(0, '参数错误');
			}
			//查找文件是否有标签
			$tag_rel_data = $this->getTagsByArcId($id);
			if (empty($tag_rel_data)) {
				jsonOut(1, '', '暂无标签');
			} else {
				$html = '';
				foreach ($tag_rel_data as $key => $val) {
					if ($val['tag_info']) {
						$html .= '<a href="#" data-id="' . $val['rel_id'] . '" class="btn btn-small default delTagBtn" style="padding: 2px 2px 2px 2px;margin: 4px 2px 4px 2px">' . $val['tag_info']['tag_name'] .
							' <i class="fa fa-close"></i>' .
							'</a>';
					}
				}
				jsonOut(1, '', $html);
			}
		}
	}
	//设置标签数据
	public function setTagData() {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('id', '');
			$tid = $this->request->post('tid', '');
			if (empty($id) || empty($tid)) {
				jsonOut(0, '参数错误');
			}
			//查询设置的标签是否存在
			$f_data = $this->tag_archives_relation_model->getDataByCondition(array('tag_id' => $tid, 'arc_id' => $id));
			if (empty($f_data)) {
				$save_data = array(
					'tag_id' => $tid,
					'arc_id' => $id,
					'create_user_id' => $this->admin_session['id'],
					'create_time' => date('Y-m-d H:i:s'),
					'update_user_id' => $this->admin_session['id'],
					'update_time' => date('Y-m-d H:i:s'),
				);
				if ($this->tag_archives_relation_model->insert($save_data)) {
					jsonOut(1, '设置成功');
				} else {
					jsonOut(0, '设置失败');
				}
			} else {
				jsonOut(0, '标签已存在');
			}
		}
	}
	//删除标签
	public function delTagData() {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('id', '');
			if (empty($id)) {
				jsonOut(0, '参数错误');
			}
			$save_data = array(
				'is_delete' => 1,
				'update_user_id' => $this->admin_session['id'],
				'update_time' => date('Y-m-d H:i:s'),
			);
			if ($this->tag_archives_relation_model->updateByCondition(array('rel_id' => $id), $save_data)) {
				jsonOut(1, '删除成功');
			} else {
				jsonOut(0, '删除失败');
			}
		}
	}
	//在线阅读
	public function onRead() {
		$this->getAuth();

		$params = array();
		$id = $this->request->param('id', 0);
		$uid = $_SESSION['think']['username'][0]['user_id'];
		//查询所属组织
		$org = Db::table('cn_user_organization_relation')
			->where('user_id', $uid)
			->field('org_id')
			->find();
		if (empty($id)) {
			jsonOut(0, '参数错误');
		}
		$data = $this->a_model->getDataByCondition(array('arc_id' => $id));
		$mark = Db::table('cn_archives')
		// ->where('file_new_name', 'like', '%' . $file['token'] . '%')
			->where('arc_id', $id)
			->field('mark')
		// ->order('file_id desc')
			->find();
		if (in_array($mark['mark'], ['2', '3', '4'])) {
			$extend_data = Db::table('cn_arc_extend_info')
				->alias('ei')
				->join('cn_arc_extend e', 'e.id = ei.arc_id')
			// ->where('file_new_name', 'like', '%' . $file['token'] . '%')
				->where('extend_id', $id)
			// ->field('arc_id,value')
			// ->order('file_id desc')
				->select();
			// var_dump($extend_data);die;
		}
		// $extend_data = $this->aei_model->where(array('arc_id' => $id))->find();
		if (empty($data)) {
			jsonOut(0, '文件不存在');
		}
		$res = $this->acf_model->where(array('arc_id' => $id))->find();
		$res1 = $this->fl_model->where(array('file_id' => $res['file_id']))->find();
		$filePath = $res1['file_save_path'];
		// $path = $this->getFilePathUrl($data['category_id'], 1, $org['org_id'], $id);
		// $filePath = $path . $data['arc_name'] . '.' . $data['arc_type'];
		//dump($filePath);die;
		$data['filePath'] = $filePath;
		$data['http'] = 'http://' . $_SERVER['HTTP_HOST'];
		$data['box_path'] = $this->storage_model->getStoragePath($data['box_id']);
		if ($data['arc_time'] == '0000-00-00 00:00:00') {
			$data['arc_time'] = date('Y-m-d');
		} else {
			$data['arc_time'] = date('Y-m-d', strtotime($data['arc_time']));
		}

		$params['data'] = $data;
		if (isset($extend_data)) {
			$params['extend_data'] = $extend_data;
		}
		$ac_data = $this->storage_model->where(array('is_delete' => 0))->select();
		$cate_tree = recursionStorage($ac_data, 'sto_id', 0, 'patent_id');
		$tree = createStorageTree($cate_tree, 'sto_id', 'patent_id', 'sto_name');
		if (empty($tree)) {
			jsonOut(0, '文件目录错误');
		}
		/* $filePath1 = $this->getFilePath($data['category_id'],1);
			         $doc_file = $filePath1['path'].$data['arc_name'].'.'.$data['arc_type'];
			         $output_file = $filePath1['path'].$data['arc_name'].'.pdf';
			 //        $doc_file=dirname(__FILE__)."/11.doc"; //源文件，DOC或者WPS都可以
			 //        $output_file=dirname(__FILE__)."/11.pdf"; //欲转PDF的文件名
			         $output_file=str_replace("\\","/",$output_file);
			         $doc_file = "file:///" . $doc_file;
			         $output_file = "file:///" . $output_file;
			         $file = word2pdf($doc_file,$output_file);
			         var_dump($file);
		*/

		$params['tree'] = $tree;

		//文件阅读记录保存
		$uid = $_SESSION['think']['username'][0]['user_id'];
		$time = date('Y-m-d H:i:s', time());

		// $prev = Db('_file_record')
		//         ->where('create_user_id',$uid)
		//         ->order('create_time desc')
		//         ->limit(0,1)
		//         ->field('file_log_desc')
		//         ->find();
		// $prevdata = $prev['log_desc'];
		// if ($prevdata !== '在线阅读') {
		//记录用户操作
		$note = [
			'file_id' => $id,
			'file_record' => 0,
			'file_log_desc' => '在线阅读',
			'create_user_id' => $uid,
			'create_time' => $time,
		];
		$record = Db::table('cn_file_record')
			->insert($note);
		// }
		return view('index@Prearc/onRead', $params);
	}
	//编辑文档信息
	public function setArc($mark) {
		$this->getAuth();

		if ($this->request->instance()->isPost()) {
			$id = $this->request->post('id');
			$arc_title = $this->request->post('arc_title');
			$arc_reference = $this->request->post('arc_reference');
			// $arc_class_num = $this->request->post('arc_class_num');
			// $arc_file_num = $this->request->post('arc_file_num');
			// $arc_total_num = $this->request->post('arc_total_num');
			// $arc_part_num = $this->request->post('arc_part_num');
			// $arc_num = $this->request->post('arc_num');
			$arc_establishment_organization = $this->request->post('arc_establishment_organization');
			$arc_establishment_person = $this->request->post('arc_establishment_person');
			$arc_year = $this->request->post('arc_year');
			$arc_rank = $this->request->post('arc_rank');
			$arc_entities_num = $this->request->post('arc_entities_num');
			$arc_borrowed = $this->request->post('arc_borrowed');
			$arc_page_num = $this->request->post('arc_page_num');
			$box_id = $this->request->post('box_id');
			$arc_storage_position = $this->request->post('arc_storage_position');
			$arc_remarks = $this->request->post('arc_remarks');
			$arc_time = $this->request->post('arc_time');
			$arc_time_limit = $this->request->post('arc_time_limit');
			$data = $this->a_model->getDataByCondition(array('arc_id' => $id));
			$code = Session::get('code');
			Session::delete('code');
			if (empty($data)) {
				jsonOut(0, '档案信息错误');
			}
			//先查询档案盒里面是否已经满了
			$h_data = $this->storage_model->getDataByCondition(array('sto_id' => $box_id));
			/*if(empty($h_data)){
				                jsonOut(0,'档案盒不能为空');
			*/
			$h_sy = $h_data['sto_available_pages'] - $h_data['to_available_pages'];
			if ($arc_page_num > $h_sy) {
				jsonOut(0, '档案盒最大还可以存放' . $h_sy . '页数据');
			}
			if (in_array($mark, ['2', '3', '4'])) {
				// var_dump('123');die;
				$data = [];
				foreach ($_POST['extend'] as $key => $value) {

					$data = [
						'extend_id' => $id,
						'arc_id' => $key,
						'value' => $value,
						'add_time' => date('Y-m-d H:i:s', time()),
					];
					// var_dump($data);die;
					$extend = db('arc_extend_info')->where('extend_id', $id)->where('arc_id', $key)->update($data);
				}
				// $extend_info = new Arc_extend_info;
				// $extend = $extend_info->saveAll($data);

			}

			$save_data = array(
				'arc_title' => $_POST['arc_title'],
				'arc_reference' => $arc_reference,
				// 'arc_class_num'=>$arc_class_num,
				// 'arc_file_num'=>$arc_file_num,
				// 'arc_total_num'=>$arc_total_num,
				// 'arc_part_num'=>$arc_part_num,
				// 'arc_num'=>$arc_num,
				'arc_establishment_organization' => $arc_establishment_organization,
				'arc_establishment_person' => $arc_establishment_person,
				'arc_year' => $arc_year,
				'arc_rank' => $arc_rank,
				'arc_entities_num' => $arc_entities_num,
				'arc_borrowed' => $arc_borrowed,
				'box_id' => $box_id,
				'arc_storage_position' => $arc_storage_position,
				'arc_remarks' => $arc_remarks,
				'arc_time' => $arc_time . " 00:00:00",
				'arc_time_limit' => $arc_time_limit,
				'arc_page_num' => $arc_page_num,
			);
			$save = $this->a_model->updateByCondition(array('arc_id' => $id), $save_data);
			// if ($mark == '1') {
			// 	$save_data = array(
			// 		'arc_title' => $_POST['arc_title'],
			// 		'arc_reference' => $arc_reference,
			// 		// 'arc_class_num'=>$arc_class_num,
			// 		// 'arc_file_num'=>$arc_file_num,
			// 		// 'arc_total_num'=>$arc_total_num,
			// 		// 'arc_part_num'=>$arc_part_num,
			// 		// 'arc_num'=>$arc_num,
			// 		'arc_establishment_organization' => $arc_establishment_organization,
			// 		'arc_establishment_person' => $arc_establishment_person,
			// 		'arc_year' => $arc_year,
			// 		'arc_rank' => $arc_rank,
			// 		'arc_entities_num' => $arc_entities_num,
			// 		'arc_borrowed' => $arc_borrowed,
			// 		'box_id' => $box_id,
			// 		'arc_storage_position' => $arc_storage_position,
			// 		'arc_remarks' => $arc_remarks,
			// 		'arc_time' => $arc_time . " 00:00:00",
			// 		'arc_time_limit' => $arc_time_limit,
			// 		'arc_page_num' => $arc_page_num,
			// 	);
			// 	$save = $this->a_model->updateByCondition(array('arc_id' => $id), $save_data);

			// } elseif ($mark == '2') {
			// 	$save_data = array(
			// 		'arc_title' => $_POST['arc_title'],
			// 		'arc_reference' => $arc_reference,
			// 		// 'arc_class_num'=>$arc_class_num,
			// 		// 'arc_file_num'=>$arc_file_num,
			// 		// 'arc_total_num'=>$arc_total_num,
			// 		// 'arc_part_num'=>$arc_part_num,
			// 		// 'arc_num'=>$arc_num,
			// 		'arc_establishment_organization' => $arc_establishment_organization,
			// 		'arc_establishment_person' => $arc_establishment_person,
			// 		'arc_year' => $arc_year,
			// 		'arc_rank' => $arc_rank,
			// 		'arc_entities_num' => $arc_entities_num,
			// 		'arc_borrowed' => $arc_borrowed,
			// 		'box_id' => $box_id,
			// 		'arc_storage_position' => $arc_storage_position,
			// 		'arc_remarks' => $arc_remarks,
			// 		'arc_time' => $arc_time . " 00:00:00",
			// 		'arc_time_limit' => $arc_time_limit,
			// 		'arc_page_num' => $arc_page_num,
			// 	);
			// 	$extend_data = array(
			// 		'arc_id' => $id,
			// 		'ptime' => $_POST['ptime'],
			// 		'pcha' => $_POST['pcha'],
			// 		'pkey' => $_POST['pkey'],
			// 		'pbrief' => $_POST['pbrief'],
			// 		'pfrom' => $_POST['pfrom'],
			// 		// 'psource' => $_POST['psource'],
			// 		'add_time' => date('Y-m-d H:i:s'),
			// 	);
			// 	$save = $this->a_model->updateByCondition(array('arc_id' => $id), $save_data);
			// 	$extend = $this->aei_model->updateByCondition(array('arc_id' => $id), $extend_data);

			// } elseif ($mark == '3') {
			// 	$save_data = array(
			// 		'arc_title' => $_POST['arc_title'],
			// 		'arc_reference' => $arc_reference,
			// 		// 'arc_class_num'=>$arc_class_num,
			// 		// 'arc_file_num'=>$arc_file_num,
			// 		// 'arc_total_num'=>$arc_total_num,
			// 		// 'arc_part_num'=>$arc_part_num,
			// 		// 'arc_num'=>$arc_num,
			// 		'arc_establishment_organization' => $arc_establishment_organization,
			// 		'arc_establishment_person' => $arc_establishment_person,
			// 		'arc_year' => $arc_year,
			// 		'arc_rank' => $arc_rank,
			// 		'arc_entities_num' => $arc_entities_num,
			// 		'arc_borrowed' => $arc_borrowed,
			// 		'box_id' => $box_id,
			// 		'arc_storage_position' => $arc_storage_position,
			// 		'arc_remarks' => $arc_remarks,
			// 		'arc_time' => $arc_time . " 00:00:00",
			// 		'arc_time_limit' => $arc_time_limit,
			// 		'arc_page_num' => $arc_page_num,
			// 	);

			// 	$extend_data = array(
			// 		'arc_id' => $id,
			// 		'vtime' => $_POST['vtime'],
			// 		'vformat' => $_POST['vformat'],
			// 		'vmin' => $_POST['vmin'],
			// 		'vkey' => $_POST['vkey'],
			// 		'vbrief' => $_POST['vbrief'],
			// 		'vfrom' => $_POST['vfrom'],
			// 		// 'vsource' => $_POST['vsource'],
			// 		'add_time' => date('Y-m-d H:i:s'),
			// 	);
			// 	$save = $this->a_model->updateByCondition(array('arc_id' => $id), $save_data);
			// 	$extend = $this->aei_model->updateByCondition(array('arc_id' => $id), $extend_data);

			// } elseif ($mark == '4') {
			// 	$save_data = array(
			// 		'arc_title' => $_POST['arc_title'],
			// 		'arc_reference' => $arc_reference,
			// 		// 'arc_class_num'=>$arc_class_num,
			// 		// 'arc_file_num'=>$arc_file_num,
			// 		// 'arc_total_num'=>$arc_total_num,
			// 		// 'arc_part_num'=>$arc_part_num,
			// 		// 'arc_num'=>$arc_num,
			// 		'arc_establishment_organization' => $arc_establishment_organization,
			// 		'arc_establishment_person' => $arc_establishment_person,
			// 		'arc_year' => $arc_year,
			// 		'arc_rank' => $arc_rank,
			// 		'arc_entities_num' => $arc_entities_num,
			// 		'arc_borrowed' => $arc_borrowed,
			// 		'box_id' => $box_id,
			// 		'arc_storage_position' => $arc_storage_position,
			// 		'arc_remarks' => $arc_remarks,
			// 		'arc_time' => $arc_time . " 00:00:00",
			// 		'arc_time_limit' => $arc_time_limit,
			// 		'arc_page_num' => $arc_page_num,
			// 	);

			// 	$extend_data = array(
			// 		'arc_id' => $id,
			// 		'dcode' => $_POST['dcode'],
			// 		'dsn' => $_POST['dsn'],
			// 		'dtest' => $_POST['dtest'],
			// 		'dpage' => $_POST['dpage'],
			// 		'dgeneral' => $_POST['dgeneral'],
			// 		'dresponse' => $_POST['dresponse'],
			// 		'ddno' => $_POST['ddno'],
			// 		'dlocation' => $_POST['dlocation'],
			// 		'dbianzhi_start' => $_POST['dbianzhi_start'],
			// 		'dbianzhi_end' => $_POST['dbianzhi_end'],
			// 		'dguidang_start' => $_POST['dguidang_start'],
			// 		'dguidang_end' => $_POST['dguidang_end'],
			// 		'dabstract' => $_POST['dabstract'],
			// 		'dclass' => $_POST['dclass'],
			// 		'dlist' => $_POST['dlist'],
			// 		'dserial_da' => $_POST['dserial_da'],
			// 		'dserial_xiao' => $_POST['dserial_xiao'],
			// 		'dtheme' => $_POST['dtheme'],
			// 		'dreference' => $_POST['dreference'],
			// 		'dfiling_clerk' => $_POST['dfiling_clerk'],
			// 		'dcomposer' => $_POST['dcomposer'],

			// 		// 'vsource' => $_POST['vsource'],
			// 		'add_time' => date('Y-m-d H:i:s'),
			// 	);
			// 	$save = $this->a_model->updateByCondition(array('arc_id' => $id), $save_data);
			// 	$extend = $this->aei_model->updateByCondition(array('arc_id' => $id), $extend_data);

			// }

			if (isset($save) || isset($extend)) {

				//先把之前的档案盒页数开放
				if (isset($data['box_id'])) {
					# code...
					$old_sto_data = $this->storage_model->getDataByCondition(array('sto_id' => $data['box_id']));
					$this->storage_model->updateByCondition(array('sto_id' => $data['box_id']), array('to_available_pages' => $old_sto_data['to_available_pages'] - $arc_page_num));
					//在把对应的档案盒页数减少
					$this->storage_model->updateByCondition(array('sto_id' => $box_id), array('to_available_pages' => $h_data['to_available_pages'] + $arc_page_num));
				}
				jsonOut(1, '文档信息编辑成功');
			} else {
				jsonOut(0, '文档信息编辑失败');
			}
		}
	}
	//上传文件
	public function upload($id) {
		$this->getAuth();

		// $params = array();
		// return view('index@Prearc/upload',$params);
		Session::set('type', $id);
		return view('index@Prearc/upload', ['id' => $id]);

	}
	//文件上传
	public function uploadFile() {
		parent::uploadFile(); // TODO: Change the autogenerated stub
	}

}
